home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DIRS.SWG / 0025_Qualified path-file.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-15  |  2KB  |  71 lines

  1. {******************************************************************
  2.  * Create a function for returning a fully qualified path/file    *
  3.  * string, with the *'s replaced by the appropriate number of ?'s.*
  4.  *                                                                *
  5.  * (C) Daniel A. Bronstein, Michigan State University, 1991.      *
  6.  *     May be used freely with acknowledgement.                   *
  7.  *****************************************************************}
  8.  
  9. unit qualify;
  10.  
  11. Interface
  12. uses dos;                    {for pathstr definition}
  13.  
  14. function fqualify(var ps:pathstr):pathstr;
  15.  
  16. Implementation
  17.  
  18. {$F+} {Far call so loading of the variable is simplified for asm.}
  19. function fqualify(var ps:pathstr):pathstr;
  20. begin
  21.   asm
  22.     push  ds                 {Save DS, else will crash after exit}
  23.     push  si                 {and just to be safe, save SI too.}
  24.     lds   si,ps              {Load address of pathstring,}
  25.     xor   ax,ax              {clear AX,}
  26.     cld                      {set direction flag and}
  27.     lodsb                    {get length byte, incrementing SI.}
  28.     mov   bx,ax              {Move length to BX and add}
  29.     mov   byte ptr[si+bx],0  {a #0 to end to create ASCIIZ string.}
  30.     les   di,@result         {Load address of the output string}
  31.     mov   bx,di              {and save it in BX.}
  32.     inc   di                 {Point past length byte of result}
  33.     mov   ah,60h             {and call DOS function 60h.}
  34.     int   21h
  35.     jnc   @ok                {If no carry then ok, else return}
  36.     mov   byte ptr[es:bx],0  {a 0 length string.}
  37.     jmp   @xit
  38. @ok:
  39.     xor   cx,cx              {Clear CX and}
  40. @0loop:
  41.     inc   di                 {loop until find end of returned}
  42.     inc   cx                 {ASCIIZ string.}
  43.     cmp   byte ptr[es:di],0  {**Note that on 286 & 386 inc/cmp is faster}
  44.     jne   @0loop             {**than CMPSB, so used here.}
  45.     mov   byte ptr[es:bx],cl {Set the length byte of the result.}
  46. @xit:
  47.     pop   si                 {Restore SI and}
  48.     pop   ds                 {DS, then}
  49.   end;                       {exit.}
  50. end;
  51. {$F-}
  52.  
  53. begin
  54. end.
  55.  
  56. { ==================================  DEMO    ============================}
  57.  
  58. PROGRAM Qualtest;
  59.  
  60. USES DOS, Qualify;
  61.  
  62. VAR
  63.   MyString, YourString : PathStr;
  64.  
  65. BEGIN
  66.   MyString := 'Foo*.*';
  67.   YourString := FQualify(MyString);
  68.   Writeln(YourString);
  69.   Readln;
  70.  
  71. END.